#include "LibraryRecord.h" 
#include <stdlib.h>
#include "../lib/rapidxml/rapidxml.hpp"

LibraryRecord::LibraryRecord(rapidxml::xml_node<> * n) {
	
	rapidxml::xml_node<> * n1 = n->first_node("rus_text");
	std::string s1 = n1->first_node("text")->value();
	textPath.push_back(s1);
	linesRed.push_back(atoi(n1->first_node("pos")->value()));
	n1 = n->first_node("eng_text");
	s1 =n1->first_node("text")->value();
	textPath.push_back(s1);
	linesRed.push_back(atoi(n1->first_node("pos")->value()));
	pathToAudio = n->first_node("rus_audio")->value();
	bookName = n->first_node("title")->value();
	
/*
	int rusIndex = record.find("|");
	std::string rus = record.substr(0,rusIndex);
	std::string other = record.substr(rusIndex + 1);
	int i = rus.rfind(" ");
	textPath.push_back(rus.substr(0,i));
	linesRed.push_back(atoi(rus.substr(i + 1).c_str()));
	int engIndex = other.find("|");
	std::string eng = other.substr(0,engIndex);
	other = other.substr(engIndex + 1);
	i = eng.rfind(" ");
	textPath.push_back(eng.substr(0,i));
	linesRed.push_back(atoi(eng.substr(i+1).c_str()));	
	i = other.find("|");
	pathToAudio = other.substr(0,i);
	other = other.substr(i + 1);
	i = other.find("|");
	bookName = other.substr(0,i);
*/	
}

//надо переписать
void swap (LibraryRecord & r, LibraryRecord & l)  {
		
	std::swap(r.textPath.at(0), l.textPath.at(1));
	std::swap(r.textPath.at(0), l.textPath.at(1));
	// for mp3...
}
